using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public abstract class GUIPanel : MonoBehaviour {
	
	public MyGUI.ResizeType resizeType;
	
	public float resizeFactor=0;
	public Vector3 originalScale;
	public Vector3 scaleVector;
	public Vector3 resizeScaleFactor;
	protected Vector3 positionVector;
	//protected List<Transform> childObjects;
		
/*		public virtual void Start() {
		
		childObjects = new List<Transform>();
		for (int i=0; i < transform.GetChildCount(); i++)
			childObjects.Add(transform.GetChild(i));
	}*/
		
	public virtual void SendClic(Vector3 position){
		
	}
	public virtual void SendRightClic(Vector3 position){
		
	}
	
	public void ResizeTo(int width, int height){
		originalScale = transform.localScale;
		
		switch (resizeType){
			case MyGUI.ResizeType.MinStretch:
				scaleVector = transform.localScale;
				resizeFactor = (width < height) ? (float)width / MyGUI.baseWidth : (float)height / MyGUI.baseHeight;
				scaleVector.x *= resizeFactor;
				scaleVector.y *= resizeFactor;
				transform.localScale = scaleVector;
			break;
			
			case MyGUI.ResizeType.MaxStretch:
				scaleVector = transform.localScale;
				resizeFactor = (width > height) ? (float)width / MyGUI.baseWidth : (float)height / MyGUI.baseHeight;
				scaleVector.x *= resizeFactor;
				scaleVector.y *= resizeFactor;
				transform.localScale = scaleVector;
			break;
			
			case MyGUI.ResizeType.Normal:
			default:
				scaleVector = transform.localScale;
				scaleVector.x *= (float) width / MyGUI.baseWidth;
				scaleVector.y *= (float) height / MyGUI.baseHeight;
				transform.localScale = scaleVector;
			break;
		}
		RepositionTo(width, height);
	}
	
	public void RepositionTo(int width, int height){
		
		float repositionFactor;
		switch (resizeType){
			case MyGUI.ResizeType.MinStretch:
				positionVector = transform.localPosition;
				repositionFactor = (width < height) ? (float)width / MyGUI.baseWidth : (float)height / MyGUI.baseHeight;
				positionVector.x *= repositionFactor;
				positionVector.y *= repositionFactor;
				transform.localPosition = positionVector;
			break;
			
			case MyGUI.ResizeType.MaxStretch:
				positionVector = transform.localPosition;
				repositionFactor = (width > height) ? (float)width / MyGUI.baseWidth : (float)height / MyGUI.baseHeight;
				positionVector.x *= repositionFactor;
				positionVector.y *= repositionFactor;
				transform.localPosition = positionVector;
			break;
			
			case MyGUI.ResizeType.Normal:
			default:
				positionVector = transform.localPosition;
				positionVector.x *= (float) width / MyGUI.baseWidth;
				positionVector.y *= (float) height / MyGUI.baseHeight;
				transform.localPosition = positionVector;
			break;
		}
	}
}
